package pe.com.cruzdelsur.dao;

import java.util.List;

import org.hibernate.SessionFactory;

import pe.com.cruzdelsur.dominio.Plantilla;
import pe.com.cruzdelsur.dominio.PlantillaDetalle;


public class PlantillaDetalleDaoImpl implements PlantillaDetalleDao {

	private SessionFactory sessionFactory;

	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}

	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	@Override
	public void insertar(PlantillaDetalle plantillaDetalle) {
		getSessionFactory().getCurrentSession().save(plantillaDetalle);

	}

	public void actualizar(PlantillaDetalle plantillaDetalle) {
		getSessionFactory().getCurrentSession().update(plantillaDetalle);

	}

	public void eliminar(PlantillaDetalle plantillaDetalle) {
		getSessionFactory().getCurrentSession().delete(plantillaDetalle);

	}

	public PlantillaDetalle obtener(int id) {
		List list = getSessionFactory().getCurrentSession()
				.createQuery("from PlantillaDetalle where estado='1' and id=?").setParameter(0, id)
				.list();
		return (PlantillaDetalle) list.get(0);
	}


	
	public List<PlantillaDetalle> listar() {
		List list = getSessionFactory().getCurrentSession()
				.createQuery("from PlantillaDetalle where estado='1' ").list();
		return list;
	}

	@Override
	public List<PlantillaDetalle> buscarDetallePorPlantilla(int plantillaId) {
	
		List list = getSessionFactory().getCurrentSession()
				.createQuery("select o from PlantillaDetalle o where o.estado='1'and o.plantilla.plantillaId=:plantillaId ").setParameter("plantillaId", plantillaId).list();
		return list;
	}




}
